
import { Router } from 'express'
import * as auth from '../middlewares/auth'
import * as signPolice from '../polices/api_v1/sign'
import * as protoPolice from '../polices/api_v1/proto'
import * as groupPolice from '../polices/api_v1/group'
import * as userPolice from '../polices/api_v1/user'
import * as signAPI from '../api/v1/sign'
import * as protoAPI from '../api/v1/proto'
import * as groupAPI from '../api/v1/group'
import * as userAPI from '../api/v1/user'

import { loadData } from '../utils'

const router = Router()

router.get('/test', (req, res, next) => res.api(loadData('flag.ini'), 0))

router.post('/login', signPolice.login, signAPI.login)
router.get('/accesstoken', auth.accessToken, signAPI.accesstoken)

router.get('/admins/group', auth.accessToken, groupAPI.getlist)
router.post('/admins/group/edit/:_id', auth.accessToken, groupPolice.edit, groupAPI.edit)
router.post('/admins/group/flag/:_id', auth.accessToken, groupPolice.setFlag, groupAPI.setFlag)
router.post('/admins/group/create', auth.accessToken, groupPolice.create, groupAPI.create)
router.post('/admins/group/remove', auth.accessToken, groupPolice.remove, groupAPI.remove)

router.get('/admins/user', auth.accessToken, userPolice.getlist, userAPI.getlist)
router.post('/admins/user/create', auth.accessToken, userPolice.create, userAPI.create)
router.post('/admins/user/edit/:_id', auth.accessToken, userPolice.edit, userAPI.edit)
router.post('/admins/user/remove', auth.accessToken, userPolice.remove, userAPI.remove)
router.post('/admins/user/status', auth.accessToken, userPolice.setStatus, userAPI.setStatus)
router.get('/admins/user/:type(username|email)', auth.accessToken, userPolice.findUser, userAPI.findUser)

router.post('/proto/:tag', auth.accessToken, protoPolice.asyncSend, protoAPI.asyncSend)

export default router